﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using BusinessAction.FileManagement;
using BusinessEntity.FileManagement;
using BusinessEntity.Common;

using System.IO;

namespace TestModule.FileManagementBusinessLayer
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class TestFileManager
    {
        public TestFileManager()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestSearchFile()
        {
            string errorMessage = string.Empty;
            string successMessage = string.Empty;

            Test.TestService.TestServiceBase oBase = new Test.TestService.TestServiceBase();

            BusinessEntity.FileManagement.MyFile oMyFile = new BusinessEntity.FileManagement.MyFile();
            //Pass any search criteria in oMessage object

            FileManager oFileManager = new FileManager();
            SortableCollection<MyFile> ooMyFiles = oFileManager.SearchFile(oBase.SessionId, oMyFile, out successMessage, out errorMessage);

            Assert.AreEqual(0, errorMessage.Length);
        }

        [TestMethod]
        public void TestGetFile()
        {
            string errorMessage = string.Empty;
            string successMessage = string.Empty;

            Test.TestService.TestServiceBase oBase = new Test.TestService.TestServiceBase();

            BusinessEntity.FileManagement.MyFile oMyFile = new BusinessEntity.FileManagement.MyFile();
            //Pass any search criteria in oMessage object

            FileManager oFileManager = new FileManager();
            SortableCollection<MyFile> ooMyFiles = oFileManager.GetFile(oBase.SessionId, out successMessage, out errorMessage);

            Assert.AreEqual(0, errorMessage.Length);
        }




        [TestMethod]
        public void TestGetFileType()
        {
            string errorMessage = string.Empty;
            string successMessage = string.Empty;

            Test.TestService.TestServiceBase oBase = new Test.TestService.TestServiceBase();

            BusinessEntity.FileManagement.MyFileType oMyFile = new BusinessEntity.FileManagement.MyFileType();
            //Pass any search criteria in oMessage object

            FileManager oFileManager = new FileManager();
            SortableCollection<MyFileType> ooMyFileTypess = oFileManager.GetFileType(oBase.SessionId, out successMessage, out errorMessage);

            Assert.AreEqual(0, errorMessage.Length);
        }

        [TestMethod]
        public void TestGetDocumentType()
        {
            string errorMessage = string.Empty;
            string successMessage = string.Empty;

            Test.TestService.TestServiceBase oBase = new Test.TestService.TestServiceBase();

            BusinessEntity.FileManagement.DocumentType oDocType = new BusinessEntity.FileManagement.DocumentType();
            //Pass any search criteria in oMessage object

            FileManager oFileManager = new FileManager();
            SortableCollection<DocumentType> oMyDocumentTypes = oFileManager.GetDocumentType(oBase.SessionId, out successMessage, out errorMessage);

            Assert.AreEqual(0, errorMessage.Length);
        }


        //[TestMethod]
        //public void TestUpdateFile()
        //{
        //    string errorMessage = string.Empty;
        //    string successMessage = string.Empty;

        //    Test.TestService.TestServiceBase oBase = new Test.TestService.TestServiceBase();

        //    BusinessEntity.FileManagement.MyFile oMyFile = new BusinessEntity.FileManagement.MyFile();
        //    //Pass any search criteria in oMessage object

        //    FileManager oFileManager = new FileManager();
        //    SortableCollection<MyFile> ooMyFiles = oFileManager.SearchFile(oBase.SessionId, oMyFile, out successMessage, out errorMessage);

        //    Assert.AreEqual(0, errorMessage.Length);
        //}

        [TestMethod]
        public void TestUploadFile()
        {
            string errorMessage = string.Empty;
            string successMessage = string.Empty;

            Test.TestService.TestServiceBase oBase = new Test.TestService.TestServiceBase();

            BusinessEntity.FileManagement.MyFile oMyFile = new BusinessEntity.FileManagement.MyFile();
            //Pass any search criteria in oMessage object
            oMyFile.FileName = "hello";
            System.IO.FileStream fs = null;
            fs = new System.IO.FileStream("c:\\Hansons.txt", FileMode.Open, FileAccess.Read);
            Byte[] blob = new Byte[fs.Length];
            fs.Read(blob, 0, blob.Length);
            fs.Close();
            oMyFile.FileContent = blob;

            FileManager oFileManager = new FileManager();
            oFileManager.UploadFile(oBase.SessionId, oMyFile, out successMessage, out errorMessage);

            Assert.AreEqual(0, errorMessage.Length);
        }

        [TestMethod]
        public void TestDeleteFile()
        {
            string errorMessage = string.Empty;
            string successMessage = string.Empty;

            Test.TestService.TestServiceBase oBase = new Test.TestService.TestServiceBase();

            BusinessEntity.FileManagement.MyFile oMyFile = new BusinessEntity.FileManagement.MyFile();
            
            

            FileManager oFileManager = new FileManager();
            oFileManager.DeleteFile(oBase.SessionId, 1, out successMessage, out errorMessage);

            Assert.AreEqual(0, errorMessage.Length);
        }




        [TestMethod]
        public void TestGetCoreUsers()
        {
            string errorMessage = string.Empty;
            string successMessage = string.Empty;

            Test.TestService.TestServiceBase oBase = new Test.TestService.TestServiceBase();

            BusinessEntity.FileManagement.CoreUser  oCoreUser = new BusinessEntity.FileManagement.CoreUser();
            //Pass any search criteria in oMessage object

            FileManager oFileManager = new FileManager();
            SortableCollection<CoreUser> oCoreUsers = oFileManager.GetCoreUsers(oBase.SessionId, out successMessage, out errorMessage);

            Assert.AreEqual(0, errorMessage.Length);
        }
    }
}
